home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Developer Utilities / Installer 4.0.3 SDK / Script Examples / System Rules - Desk Accessory / daRules.r < prev    next >
Encoding:
Text File  |  1994-11-15  |  16.9 KB  |  495 lines  |  [TEXT/MPS ]

  1. //
  2. //    daRules.r
  3. //
  4. //        Includes : system version screening, as well as customized user interface 
  5. //        and installation contents, based on existing system version of selected 
  6. //        target volume.
  7. //
  8. //        This example will install a Desk Accessory with the method proper to
  9. //        the existing system folder on the selected target volume. Installation
  10. //        of a Desk Accessory was chosen for this example because this is one of
  11. //        the many cases where you may need to provide different installations
  12. //        based upon which version of the operating system the user has.
  13. //
  14. //        Your needs may differ from this example. Many developers produce
  15. //        applications that are dependent on System 7, and will not run under
  16. //        System 6. In those cases, simply add a package containing your software
  17. //        if the proper system version is found on the selected target volume.
  18. //
  19. //        If a proper system version cannot be found on the target volume
  20. //        you may add the rule clause ReportVolError to dim or disable the Install
  21. //        button in the dialog to prevent the user from installing software
  22. //        that is inappropriate for the selected volume.
  23. //
  24. //        In this example we have arbitrarily chosen System 6.0 as the minimum
  25. //        system required for installation. Your Desk Accessory may have different
  26. //        requirements.
  27. //
  28. //        You may wish to allow the user to install software that falls outside
  29. //        of the recommended installation. Use Custom Install for these cases.
  30. //
  31. //        This example checks for system version by checking the file version
  32. //        of the System file on the selected target volume. This is not necessarily
  33. //        the version of the currently running operating system. Users may have
  34. //        different versions of system folders on different hard disks. The system
  35. //        version that will be checked is that of the blessed system folder
  36. //        on the currently selected target volume.
  37. //
  38. //        The CheckFileVersion call will look for an active system folder on 
  39. //        the selected target volume when checking the version of the System
  40. //        file. The target spec used in the CheckFileVersion call uses the path
  41. //        "special-macs:" which will look for an existing blessed system folder.
  42. //        Once the blessed system folder has been found, target spec will 'point'
  43. //        to the System file within the blessed system folder. If no blessed system
  44. //        folder is found, path "special-macs:" will default to ":System Folder:".
  45. //        In the case where the user has removed the Finder file from folder named
  46. //        "System Folder" that still contains a copy of the System file, this check
  47. //        for an existing system version on the target volume may be erroneous.
  48. //
  49. //
  50. //        IMPORTANT: As of Installer version 4.0.3, the ReportVolError and
  51. //        ReportSysError rule clauses do not function correctly when used 
  52. //        within the Global framework. Both rule clauses should disable the 
  53. //        Install button, and ReportSysError should disable the Switch Disk 
  54. //        button. Currently, when either of these rule clauses is evoked from 
  55. //        within the Global framework neither the Install or Switch Disk buttons 
  56. //        are disabled. Both rule clauses do work correctly within the Easy and 
  57. //        Custom frameworks. As a result, it is recommended that Report Error 
  58. //        clauses be implemented within Easy and Custom frameworks exclusively.
  59. //
  60. //        mark young • 08/17/94
  61. //
  62. //        Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
  63. //
  64.  
  65. #include "InstallerTypes.r"
  66.  
  67.  
  68. // constants for packages, comments, comment text
  69. #define     k70Package            200        // package for 7.0
  70. #define     k60Package            300        // package for 6.0
  71.  
  72. #define     kCurrentReleaseDate    8151994    // dummy date ( just today's date )
  73. #define     kCurrentVersion        403     // dummy version ( from installer vers )
  74.  
  75. // target spec of system file for comparing system versions
  76. // as well as the target spec for 6.0 installs
  77. #define     kSystemFileTarget         20000
  78.  
  79. #define     kKeyCaps70FileTarget     20001
  80.  
  81. // source spec of Key Caps file ( for both 7.0 and 6.0 installs )
  82. #define     kKeyCapsSourceSpec         20002
  83.  
  84. #define     kEasy70Rule                8070
  85. #define     kEasy60Rule                8060
  86.  
  87. #define     kCustom70Rule            9070
  88. #define     kCustom60Rule            9060
  89.  
  90. #define     kBadVersionRule            9999
  91.  
  92.  
  93. // • easy install setup
  94.  
  95. // easy install framework uses ID other than 765 or 766
  96. // recommended to always use ID 764
  97. resource 'infr' (764) {
  98.     format0 {{
  99.         // execute first true rule
  100.         pickFirst, { kEasy70Rule, kEasy60Rule,     // check system version 
  101.                      kBadVersionRule },         // if not supported give error
  102.                                                      
  103.     }}
  104. };
  105.  
  106. resource 'inrl' ( kEasy70Rule ) {
  107.     format0 {{
  108.         // check for 7.0 or greater
  109.         CheckFileVersion{     kSystemFileTarget,     // target file spec
  110.                             7,                     // major revision
  111.                             0,                     // minor revision
  112.                             release,             // release stage
  113.                             0 },                // incremental version
  114.         
  115.         // if 7.0 or greater add System 7 package
  116.         AddPackages{{ k70Package }},
  117.         AddUserDescription{ "Install KeyCaps Desk Accessory "
  118.                             "for use under System 7." },
  119.     }}
  120. };
  121.  
  122. resource 'inrl' ( kEasy60Rule ) {
  123.     format0 {{
  124.         // check for 6.0 or greater
  125.         CheckFileVersion{     kSystemFileTarget,     // target file spec
  126.                             6,                     // major revision
  127.                             0,                     // minor revision
  128.                             release,             // release stage
  129.                             0 },                // incremental version
  130.         
  131.         // if 6.0 or greater add System 6 package
  132.         AddPackages{{ k60Package }},
  133.         AddUserDescription{ "Install KeyCaps Desk Accessory "
  134.                             "for use under System 6." },
  135.     }}
  136. };
  137.  
  138.  
  139. // • custom install setup
  140.  
  141. // custom install framework always uses ID of 766
  142. resource 'infr' (766) {
  143.     format0 {{
  144.         // execute first true rule
  145.         pickFirst, { kCustom70Rule, kCustom60Rule,     // check system version, 
  146.                      kBadVersionRule },                // if not supported give error
  147.                                                     
  148.     }}
  149. };
  150.  
  151. // rule that checks system version of target volume
  152. resource 'inrl' ( kCustom70Rule ) {
  153.     format0 {{
  154.         // this returns false unless system version is greater than 7.0
  155.         CheckFileVersion{     kSystemFileTarget,         // target file spec
  156.                             7,                         // major revision
  157.                             0,                         // minor revision
  158.                             release,                 // release stage
  159.                             0 },                    // incremental version
  160.         
  161.         AddCustomItems{{ k70Package }},
  162.     }}
  163. };
  164.  
  165. // rule that checks system version of target volume
  166. resource 'inrl' ( kCustom60Rule ) {
  167.     format0 {{
  168.         // this returns false unless system version is greater than 6.0
  169.         CheckFileVersion{     kSystemFileTarget,         // target file spec 
  170.                             6,                         // major revision
  171.                             0,                         // minor revision
  172.                             release,                 // release stage
  173.                             0 },                    // incremental version
  174.         
  175.         AddCustomItems{{ k60Package }},
  176.     }}
  177. };
  178.  
  179. // • used in both easy and custom
  180.  
  181. // generate an error symbol, disable INSTALL button, display an error message
  182. resource 'inrl' ( kBadVersionRule ) {
  183.     format0 {{
  184.         ReportVolError{ "System 6.0 or greater required for installation !!" }
  185.     }}
  186. };
  187.  
  188. // • packages
  189.  
  190. // 7.0 or greater
  191. resource 'inpk' ( k70Package ) {
  192.     format0 {
  193.         showsOnCustom,            // if this was a subpackage, 
  194.                                 // it would be listed in Custom Install
  195.                                 
  196.         removable,                // include this package or subpackage 
  197.                                 // as a removeable item
  198.                                 
  199.         dontForceRestart,        // don't make  user reboot  after installation
  200.         k70Package,                // 'inpc' resource ID ( item defined below )
  201.         0,                        // Package size ( if 0, filled in by ScriptCheck )
  202.         
  203.         "KeyCaps DA in Apple Menu", // Custom Install selection text
  204.                                 
  205.                                 
  206.         {    // Package parts list ( all the stuff to be include in package )
  207.             // These parts can be 'inpk', 'infa', 'inra', 'inr#', 'inrm',
  208.             // 'inff', 'infm', 'inaa', 'inat', 'inat', or 'inbb'
  209.                                 
  210.         'infa', 1070;            // file atom
  211.                                 // 7.0 Key Caps Desk Acessory
  212.         },
  213.     }
  214. };
  215.  
  216. // 6.0 or greater
  217. resource 'inpk' ( k60Package ) {
  218.     format0 {
  219.         showsOnCustom,            // if this was a subpackage, 
  220.                                 // it would be listed in Custom Install
  221.                                 
  222.         removable,                // include this package or subpackage 
  223.                                 // as a removeable item
  224.                                 
  225.         dontForceRestart,        // don't make  user reboot  after installation
  226.         k70Package,                // 'inpc' resource ID ( item defined below )
  227.         0,                        // Package size ( if 0, filled in by ScriptCheck )
  228.         
  229.         "KeyCaps DA in System File", // Custom Install selection text
  230.                                 
  231.                                 
  232.         {    // Package parts list ( all the stuff to be include in package )
  233.             // These parts can be 'inpk', 'infa', 'inra', 'inr#', 'inrm',
  234.             // 'inff', 'infm', 'inaa', 'inat', 'inat', or 'inbb'
  235.                                 
  236.         'inra', 1060;            // resource atom
  237.                                 // 6.0 Key Caps Desk Acessory
  238.         },
  239.     }
  240. };
  241.  
  242.  
  243.  
  244. // • package comments
  245.  
  246. //     NOTE: The values that are assigned to the Custom Package Information 
  247. //    resource fields do not actually have any affect on the installation and 
  248. //    are ignored during installation. They can however assist the user in 
  249. //    choosing which packages they would like to include in their Custom 
  250. //    Installation or Custom Removal.
  251.  
  252. //     The following included file contains the icons for the two package comments.
  253. //     I created the file with the icon resources ( 'ICN#', 'icl4' and 'icl8' )
  254. //     by opening the application to be installed within ResEdit. I then copied 
  255. //    the 'ICN#', 'icl4' and 'icl8' icon resources into a new ResEdit file called 
  256. //    "Icons.rsrc" and assigned the resource items an ID of 9128, since their 
  257. //    original resource ID's had a value that was illegal for use with 'inpc' 
  258. //    resources ( they must be over 1024 ).
  259. //
  260. //     - An alternative to this method is to derez the application and to paste 
  261. //    the resulting resource definitions into this script file and to let the Rez 
  262. //    command build the icons every time that the installer script is Rezzed. 
  263. //    If you happen to forget to include the resources for the icons, ScriptCheck 
  264. //    will complain, but you will still be able to use the Rezzed installer script 
  265. //    to successfully perform an installation. 
  266.  
  267. include "Icons.rsrc";
  268.  
  269. resource 'inpc' ( k70Package ) {
  270.     format1 {
  271.         kCurrentReleaseDate,    // Date
  272.         kCurrentVersion,        // Version
  273.  
  274.         20 * 1024,                // RAM requirement for this package.
  275.                                 // This number is in bytes. To generate value of
  276.                                 // 1 meg in the dialog use ( 1000 * 1024 )
  277.                         
  278.         9128,                    // Icon rsrc ID ( 'ICON', 'ICN#', 'icl4', 'icl8' )
  279.                                 // - ID must be greater than 1024
  280.                                 // - resource item in rezzed script file
  281.  
  282.         k70Package,                // 'TEXT' resource ID of item  
  283.                                 // containing package description
  284.     }
  285. };
  286.  
  287. resource 'inpc' ( k60Package ) {
  288.     format1 {
  289.         kCurrentReleaseDate,    // Date
  290.         kCurrentVersion,        // Version
  291.  
  292.         20 * 1024,                // RAM requirement for this package.
  293.                                 // This number is in bytes. To generate value of
  294.                                 // 1 meg in the dialog use ( 1000 * 1024 )
  295.                         
  296.         9128,                    // Icon rsrc ID ( 'ICON', 'ICN#', 'icl4', 'icl8' )
  297.                                 // - ID must be greater than 1024
  298.                                 // - resource item in rezzed script file
  299.  
  300.         k60Package,                // 'TEXT' resource ID of item  
  301.                                 // containing package description
  302.     }
  303. };
  304.  
  305.  
  306. // The following resource items can easily be created manually by creating 'TEXT' 
  307. //  resource items in a file and including that file in this script.
  308. // USE: include "fileWithTextItem.rsrc";    
  309. // NOTE : resource includes use "include" instead of "#include" 
  310. //         and are terminated with a semicolon.
  311.  
  312. data 'TEXT' ( k70Package ) {
  313.     "This is some sample text that would describe what the 7.0 compatible "
  314.     "package contains."
  315. };
  316.  
  317. data 'TEXT' ( k60Package ) {
  318.     "This is some sample text that would describe what the 6.0 compatible "
  319.     "package contains."
  320. };
  321.  
  322.  
  323. // • file atoms
  324.  
  325. // file atom for the actual DA file to be installed for System 7
  326. resource 'infa' (1070) {
  327.     format1 {
  328.         deleteWhenRemoving,                //  Delete on deinstall
  329.         deleteWhenInstalling,            //  Remove preexisting
  330.         copy,                            //  Copy on Install
  331.  
  332.         dontIgnoreLockedFile,            //    Respect file locking
  333.         dontSetFileLocked,                //  Don't lock file after installation
  334.         useSrcCrDateToCompare,            //    Use date instead of version
  335.         srcNeedNotExist,                //    Install if new file
  336.         rsrcForkInRsrcFork,                //    Rrsc info stored in rsrc fork
  337.         leaveAloneIfNewer,                //    Don't update a newer file
  338.         updateExisting,                    //    Update if file already exists
  339.         copyIfNewOrUpdate,                //    Create new or update existing
  340.         rsrcFork,                        //    Copy rsrc info
  341.         dataFork,                        //    Copy data info
  342.         0,                                //    Size ( filled in by ScriptCheck )
  343.         
  344.         0x0,                            //    Finder attribute flags
  345.                                         //    ( filled in by ScriptCheck )
  346.                                         
  347.         kKeyCaps70FileTarget,    //  target spec for DA file
  348.         {    
  349.             kKeyCapsSourceSpec, //     Source spec for DA file
  350.             0,                     //     Data fork size ( filled in by ScriptCheck )
  351.             0                    //     Rsrc fork size ( filled in by ScriptCheck )
  352.         },
  353.         
  354.         0,                            //  The source version number in BCD format
  355.                                     //  ( if this value is zero, tgt file will
  356.                                     //    always be assumed to be older )
  357.                                     
  358.         0,                            //     Version compare procedure ( 0 : none )
  359.         
  360.         0,                            //  Atom extender resource ID ( 0 : none )
  361.         
  362.         ""                            //     Atom description 
  363.                                     //  ( if none installer will use filename )
  364.     }
  365. };
  366.  
  367. // • resource atoms
  368.  
  369. // resource atom for the DA rsrc item to be installed for System 6
  370. resource 'inra' (1060) {
  371.     format1 {
  372.         deleteWhenRemoving,                //  Delete on deinstall
  373.         dontDeleteWhenInstalling,        //  Do not remove preexisting
  374.         copy,                            //  Copy on Install
  375.         
  376.         leaveAloneIfNewer,                //  Do not update a newer file
  377.         tgtRequired,                    //  Target file must already exist
  378.         updateExisting,                    //  Update an existing file
  379.         copyIfNewOrUpdate,                //  Copy whether target exists or not
  380.         ignoreProtection,                //  Don't respect file locking
  381.         srcNeedExist,                    //  Source file must exist
  382.         byName,                            //  Use name instead of rsrc ID
  383.         nameMustMatch,                    //  Ignored when using 'byID'
  384.         
  385.         0,                    // TARGET - total resource size after installation
  386.                             // ( filled by ScriptCheck if 0 )
  387.                             
  388.         kSystemFileTarget,    // TARGET - file spec ( 'intf' )
  389.         'DRVR',                // TARGET - resource type 
  390.         0,                    // TARGET - resource ID ( ignored when using 'byName' )
  391.         
  392.         0x0,                // TARGET - resource attribute flags 
  393.                             // ( filled in by ScriptCheck if 0x0 )
  394.  
  395.         "\0x00Key Caps",    // TARGET - resource name 
  396.                             // this field must be when installing by ID
  397.         {    
  398.             kKeyCapsSourceSpec,    // SOURCE - file spec ( 'infs' )
  399.             'DRVR',                // SOURCE - resource type
  400.             14,                    // SOURCE - resource ID ( ignored when using 'byName' )
  401.             0,                    // SOURCE - resource size ( filled by ScriptCheck if 0 )
  402.             "\0x00Key Caps",    // SOURCE - resource name
  403.         },    
  404.         
  405.         0x0,                // SOURCE - version number for comparisons
  406.                             // 0x0 specifies not to perform version comparison
  407.                             
  408.         0,                    // 'invc' code resource - version comparison routine 
  409.                             // ( none used here )
  410.         
  411.         0,                    // 'inex' resource definition for atom extender
  412.                             // ( none used here )
  413.                             
  414.         "Key Caps DA",        // resource atom description                    
  415.     }
  416. };
  417.  
  418.  
  419. // • file specs
  420.  
  421. // target file spec to Apple Menu for Key Caps install to System 7
  422. resource 'intf' (kKeyCaps70FileTarget) {
  423.     format1 {
  424.         noSearchForFile,                 // use default search path
  425.         
  426.         TypeCrMustMatch,                 // If this is set to TypeCrMustMatch
  427.                                         // then a file with a different type
  428.                                         // and creator than those specified
  429.                                         // below will not be replaced.
  430.                                         // If this is set to TypeCrNeedNotMatch
  431.                                         // then type and creator of an existing
  432.                                         // target file are ignored.
  433.         
  434.         // The Type and Creator fields will be used to set the
  435.         // file's Type and Creator when a new file is created. 
  436.         'dfil',                         // TYPE for new file
  437.         'keyc',                         // CREATOR for new file
  438.         
  439.         0,                                 // finder attribute flags
  440.                                         // filled by ScriptCheck is value is 0
  441.         
  442.         1,                                  // creation date for new file
  443.         1,                                  // modification date for new file
  444.                                         // NOTE: DATE values are filled
  445.                                         // by ScriptCheck if the value is 1
  446.                                             
  447.         0,                                 // search proc ID ( 'insp' ), none used
  448.         
  449.         "special-amnu:Key Caps"         // path to target file
  450.         }
  451.     };
  452.  
  453. // source file spec for Key Caps for System 7 and for System 6
  454. resource 'infs' ( kKeyCapsSourceSpec ) {
  455.     'dfil',                        // TYPE for file search
  456.     'keyc',                        // CREATOR for file search
  457.  
  458.     0x1,                        // creation DATE for source file
  459.                                 // ( value of 1, filled in by ScriptCheck
  460.                                 
  461.     noSearchForFile,            // IGNORED in Installer 4.0.x
  462.     TypeCrMustMatch,            // TYPE, CREATOR must match file on install disk
  463.     "Disk 1:Key Caps"            // PATH to source file        
  464. };
  465.  
  466.  
  467.  
  468. // target file spec for checking System version on target
  469. // and for installing DA resource item to System file for System 6
  470. resource 'intf' (kSystemFileTarget) {
  471.     format1 {
  472.         noSearchForFile,                 // use default search path
  473.         
  474.         TypeCrNeedNotMatch,        // • because system type is different
  475.                                 // • under System 6 and 7 need to set
  476.                                 // • this flag to ignore type and creator
  477.                                 // • so that this file spec can be used
  478.                                 // • for both systems !!
  479.         
  480.         // These two fields will be ignored because TypeCrNeedNotMatch
  481.         // and this target spec is only used for referencing the System
  482.         // file. Nothing is actually installed using this target spec.
  483.         // But it woulda looked silly to give these bogus values...
  484.         'zsys',                         // TYPE for file
  485.         'MACS',                         // CREATOR for file
  486.         
  487.         0,                                 // finder attribute flags        
  488.         1,                                  // creation date for new file
  489.         1,                                  // modification date for new file
  490.         0,                                 // search proc ID ( 'insp' ), none used
  491.         
  492.         "special-macs:System"    // path to target file
  493.         }
  494.     };
  495.